19. Process Shutdown Demo

ANDK L4 37 Process Shutdown Demo SC 2 V2

Terminating a process

  1. Make sure you are using a device or emulator running at least API level 28. This is easier to set up for an emulator.
  2. Make sure adb is installed. If not, see instructions below.
  3. Make sure your app is in the background - this only happens when the app is in the background. You can do this by hitting the home button.
  4. Run the command:
adb shell am kill com.example.android.dessertpusher

This will stop the process as-if it had been stopped by the Android operating system.

Adding ADB to your path

If you try running adb in a terminal and you see something similar to the message below, read on:

ADB (Android Debug Bridge) is command line tool, and if you want to use it from the command line, it needs to be part of your path. First you’ll find where the adb executable lives, then you’ll add that to your path.

1. Find the platform-tools folder which contains adb:

Adb is part of the Android SDK, which is downloaded as part of Android Studio. You can find the location of this SDK by going to Tools -> SDK Manager

ADB is located in this location, followed by platform-tools/ so in the example above, you could find adb in:

/Users/lmf/Library/Android/sdk/platform-tools/

2. Add adb to your path:

Adding a variable to your path varies by platform, follow the instructions below to add the platform-tools location you located above.

Windows

  1. Go to Advanced system settings:
    • Windows 8 and 10: Search -> System (Control Panel) -> Advanced system settings
    • Windows 7: Right-click Computer -> Properties -> Advanced system settings
    • Windows Vista: Right click My Computer -> Properties -> Advanced system settings
    • Windows XP: Start -> Control Panel -> System -> Advanced tab
  2. Click Environment Variables
  3. Find the System Variables section and then look to see if you have a PATH environment variable:
    • If you find one, click Edit
    • If you do not find one, click New to add one
  4. Add ;<Path to platform-tools> to the end of the Variable value box
  5. Click OK on all windows to save
  6. Ensure you can run adb by typing:
    • adb
  7. You should see output, including something like:

Mac/Linux

Adding a path variable is done using the terminal on Mac/Linux.

  1. Open a Terminal
  2. Create a .bash_profile file if you don’t have one already. This is a configuration file for bash - it’s executed when you start bash:
    • touch ~/.bash_profile
  3. Open up the ~/.bash_profile file in your preferred text editor:
    • open ~/.bash_profile
  4. Add the following to your .bash_profile file and save:
    • export PATH=<Path to platform-tools>:$PATH
  5. Either restart your terminal, or enter:
    • source ~/.bash_profile
  6. Ensure you can run adb by typing:
    • adb
  7. You should see output, including something like: